package com.liruo.learn.spring.security.controller;

import com.liruo.learn.spring.security.auth.AuthenticUser;
import com.liruo.learn.spring.security.resphandler.BaseResp;
import com.liruo.learn.spring.security.resphandler.BusinessException;
import com.liruo.learn.spring.security.resphandler.Some2XXException;
import com.liruo.learn.spring.security.user.User;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:liruo
 * @Date:2023-05-27-13:47:37
 * @Desc
 */

@RestController
@RequestMapping("/axiosTest")
public class AxiosTestController {
    private AuthenticUser user;

    @GetMapping("/{userId}")
    public BaseResp<AuthenticUser> getUser(@PathVariable("userId") Long userId) {
        if (user == null) {
            return BaseResp.ok(new AuthenticUser(new User(userId, "test", "test", "email", "phone")));
        }
        return BaseResp.ok(user);
    }

    @PostMapping
    public BaseResp<AuthenticUser> postUser(@RequestBody AuthenticUser user) {
        this.user = user;
        return BaseResp.ok(this.user);
    }

    @GetMapping("/no2xxerr")
    public BaseResp<AuthenticUser> no2xxerr() {
        throw new BusinessException("no2xxerr");
    }
    @GetMapping("/2xxerr")
    public BaseResp<AuthenticUser> a2xxerr() {
        throw new Some2XXException("2xxerr");
    }
}
